package com.lanou3g.baidumusic.main.mainactivity;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.lanou3g.baidumusic.R;
import com.lanou3g.baidumusic.main.mainfragment.FindFragment;
import com.lanou3g.baidumusic.main.mainfragment.MainFragmentAdapter;
import com.lanou3g.baidumusic.main.mainfragment.MineFragment;
import com.lanou3g.baidumusic.main.mainfragment.MovingFragment;
import com.lanou3g.baidumusic.main.mainfragment.MusicFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 17/3/16.
 */

public class MainFragment extends BaseFragment{

    private String [] titles = {"我的","音乐","动态","发现"} ;

    private TabLayout tabLayout ;
    private ViewPager viewPager ;

    private List<Fragment> fragments ;
    private MainFragmentAdapter adapter ;


    @Override
    public int setLayout() {
        return R.layout.fragment_main;
    }

    @Override
    public void initView(View view) {
        tabLayout = (TabLayout) view.findViewById(R.id.fragment_main_tl_tl);
        viewPager = (ViewPager) view.findViewById(R.id.fragment_main_vp_vp);

        fragments = new ArrayList<>();
        fragments.add(new MineFragment());
        fragments.add(new MusicFragment());
        fragments.add(new MovingFragment());
        fragments.add(new FindFragment());


    }

    @Override
    public void initData() {

        tabLayout.setTabTextColors(Color.GRAY , Color.WHITE);
//        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#88d7ff"));

        adapter = new MainFragmentAdapter(getChildFragmentManager() , fragments);

        tabLayout.setupWithViewPager(viewPager);
        viewPager.setAdapter(adapter);


        for (int i = 0; i < titles.length; i++) {
            tabLayout.getTabAt(i).setText(titles[i]);
        }

//        for (int i = 0; i < adapter.getCount(); i++) {
//            View tabView = adapter.getTabView(i , getContext());
//
//            TabLayout.Tab tab = tabLayout.getTabAt(i);
//
//            tab.setCustomView(tabView);
//        }


    }
}
